/*
 * @Description: 转换驼峰式
 * @Author: zzj
 * @Date: 2021-09-10 14:15:19
 * @LastEditors: zzj
 * @LastEditTime: 2021-09-14 21:28:52
 */

/*
var s1 = "get-element-by-id"
封装函数 render(s1);结果：getElementById
 */
var s1 = "get-element-by-id"
function render1(s1){
    var s2 = [];
    var s_up = s1.toUpperCase();
    for(var i=0;i<=s1.length;i++){
        if(s1[i] != "-"){
            s2.push(s1[i]);
        }else{
            s2.push(s_up[i+1]);
            i++;
        }
    }
    console.log(s2.join(""))
}
render1(s1);

function render2 (s) {
    return s.replace(/-\w/g, function(x) {
        return x.slice(1).toUpperCase();
    })
}
console.log(render2(s1));